local qianxun = fk.CreateSkill {

  name = "joyex__qianxun",

  tags = { Skill.Compulsory, },

}



qianxun:addEffect(fk.CardEffecting, {
  name = "joyex__qianxun",
  events = {fk.CardEffecting},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(qianxun.name) and target == player and data.card.type == Card.TypeTrick and #data:getAllTargets() == 1 and not player:isKongcheng()
  end,
  on_cost = function(self, event, target, player, data)
    local cards = player.room:askForCard(player,1,player.hp,false,qianxun.name,true,".","#joyex__qianxun-choose:::"..player.hp)
    if #cards > 0 then
      event:setCostData(self, cards)
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    player:addToPile("joyex__qianxun", event:getCostData(self), false, qianxun.name)
  end,
})

qianxun:addEffect(fk.EventPhaseChanging, {
  name = "#joyex__qianxun_delay",
  mute = true,
  events = {fk.EventPhaseChanging},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    return data.to == Player.NotActive and #player:getPile("joyex__qianxun") > 0
  end,
  on_use = function(self, event, target, player, data)
    local dummy = Fk:cloneCard("zixing")
    dummy:addSubcards(player:getPile("joyex__qianxun"))
    local room = player.room
    room:obtainCard(player, dummy, false)
  end,
})

return qianxun